Instructions

Answer the following questions and complete the exercises in RMarkdown. Please embed all of your code and push your final work to your repository. Your final lab report should be organized, clean, and run free from errors. Remember, you must remove the # for the included code chunks to run. Be sure to add your name to the author header above. For any included plots, make sure they are clearly labeled. You are free to use any plot type that you feel best communicates the results of your analysis.

Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!

Load the libraries

library(tidyverse)
library(janitor)
library(ggmap)

Load the Data

We will use two separate data sets for this homework.

  1. The first data set represent sightings of grizzly bears (Ursos arctos) in Alaska.

  2. The second data set is from Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.

  3. Load the grizzly data and evaluate its structure.

grizzly <- read_csv("data/bear-sightings.csv")
## Rows: 494 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (3): bear.id, longitude, latitude
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
  1. Use the range of the latitude and longitude to build an appropriate bounding box for your map.
grizzly %>% 
  select(latitude, longitude) %>% 
  summary()
##     latitude       longitude     
##  Min.   :55.02   Min.   :-166.2  
##  1st Qu.:58.13   1st Qu.:-154.2  
##  Median :60.97   Median :-151.0  
##  Mean   :61.41   Mean   :-149.1  
##  3rd Qu.:64.13   3rd Qu.:-145.6  
##  Max.   :70.37   Max.   :-131.3
lat <- c(55.02, 70.37)
long <- c(-166.2, -131.3)
bbox <- make_bbox(long, lat, f = 0.03)
  1. Load a map from stamen in a terrain style projection and display the map.
register_stadiamaps("ca47a687-603d-4e29-be60-6e69cdcb97ae", write = FALSE)
map1 <- get_stadiamap(bbox, maptype = "stamen_terrain", zoom=7)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## ℹ 196 tiles needed, this may take a while (try a smaller zoom?)
ggmap(map1)

  1. Build a final map that overlays the recorded observations of grizzly bears in Alaska.
ggmap(map1) + 
  geom_point(data = grizzly, aes(longitude, latitude), size=.8, color = "darkred") +
  labs(x= "Longitude", y= "Latitude", title="Grizzly Bear Sightings")

Let’s switch to the wolves data. Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.

  1. Load the data and evaluate its structure.
wolves <- read_csv("data/wolves_data/wolves_dataset.csv")
## Rows: 1986 Columns: 23
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (4): pop, age.cat, sex, color
## dbl (19): year, lat, long, habitat, human, pop.density, pack.size, standard....
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
  1. How many distinct wolf populations are included in this study? Make a new object that restricts the data to the wolf populations in the lower 48 US states.
wolves %>% 
  group_by(pop) %>% 
  summarise(n_individuals = n())
## # A tibble: 17 × 2
##    pop     n_individuals
##    <chr>           <int>
##  1 AK.PEN            100
##  2 BAN.JAS            96
##  3 BC                145
##  4 DENALI            154
##  5 ELLES              11
##  6 GTNP               60
##  7 INT.AK             35
##  8 MEXICAN           181
##  9 MI                102
## 10 MT                351
## 11 N.NWT              67
## 12 ONT                60
## 13 SE.AK              10
## 14 SNF                92
## 15 SS.NWT             34
## 16 YNP               383
## 17 YUCH              105

There are 17 distinct wolf populations

wolves_restricted <- wolves %>% 
  filter(pop == "MT" | pop == "MI" | pop == "GTNP" | pop == "YNP" | pop == "SNF")
  1. Use the range of the latitude and longitude to build an appropriate bounding box for your map.
wolves_restricted %>% 
  select(lat, long) %>% 
  summary()
##       lat             long        
##  Min.   :43.82   Min.   :-110.99  
##  1st Qu.:44.60   1st Qu.:-110.99  
##  Median :46.15   Median :-110.55  
##  Mean   :45.80   Mean   :-106.49  
##  3rd Qu.:46.83   3rd Qu.:-110.55  
##  Max.   :47.75   Max.   : -86.82
lat1 <- c(43.5, 48)
long1 <- c(-110.99, -86.82)
bbox1 <- make_bbox(long1, lat1, f = 0.03)
  1. Load a map from stamen in a terrain-lines projection and display the map.
map2 <- get_stadiamap(bbox1, maptype = "stamen_terrain_lines", zoom=7)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
ggmap(map2)

  1. Build a final map that overlays the recorded observations of wolves in the lower 48 states.
ggmap(map2) + 
  geom_point(data = wolves_restricted, aes(long, lat), size=0.4) +
  labs(x= "Longitude", y= "Latitude", title = "Wolf Populations")

  1. Use the map from #9 above, but add some aesthetics. Try to fill and color by population.
ggmap(map2) + 
  geom_point(data = wolves_restricted, aes(long, lat, color = pop), size=4) +
  labs(x= "Longitude", 
       y= "Latitude", 
       title = "Wolf Populations",
       color = "Population")

Push your final code to GitHub!

Please be sure that you check the keep md file in the knit preferences.